$(document).ready(function () {
    $('#load-more').click(function () {
        url = '/v1/authors/';
        $.ajax({
            method: 'GET',
            url: '/v1/authors/',
            dataType: 'json',
            success: function (data) {
                api_url = data['next'];
                if (api_url == null){
                    $('#load-more').val('已加载全部');
                    $('#load-more').attr('disabled',true);
                    api_url = 'v1/authors/';
                }
                $('p').hide();
                // let api_url = data['next'];
                // $('p').hide()
                // $("#div1").html(result[1].name)
                for (let i = 0; i < data.length; i++) {
                    $('#ele-table-body').append(
                        ' <tr>\n' +
                        ' <th scope="col">' + data[i]['id'] + '</th>\n' +
                        ' <th scope="col">' + data[i]['name'] + '</th>\n' +
                        // ' <th scope="col"><a href="/detail/' + results[i]['pk'] +'" rel="external nofollow" >' + results[i]['name'] + '</a></th>\n' +
                        ' <th scope="col">' + data[i].orgs.length + '</th>\n' +
                        ' </tr>'
                    )
                }
            }
        })
    })
});

// 修改
$(document).ready(function () {
    $('#edit-confirm-btn').click(function () {
        var name = $('#name').val();
        var distance = $('#distance').val();
        var adderss = $('#address').val();
        var time = $('#time').val();
        var score = $('#score').val();
        var comments = $('#comments').val();
        var sell = $('#sell').val();
        var pk = $('#pk').val();
        $.ajax({
            type: 'PATCH',
            url: '/detail/' + pk,
            data: {
                "name": name,
                "distance": distance,
                "address": adderss,
                "time": time,
                "score": score,
                "comments": comments,
                "sell": sell,
            },
            success: function (data) {
                if (data.status == 'ok') {
                    console.log('success');
                    location.reload();
                }
            }
        })
    })
})
